package org.vaadin.nf4v.ext.config.util;

/**
 * String utilities.
 */
public class StringUtil {

    /**
     * @param string string to test
     * @return true if string is null or empty
     */
    public static boolean isBlank(String string) {
        return string == null || "".equals(string.trim());
    }

    /**
     * Almost the same as String.split(), but with trimmed tokens
     *
     * @param string string to split
     * @param regex  separator regex
     * @return array of trimmed tokens.
     */
    public static String[] split(String string, String regex) {
        String[] res = string.split(regex);
        for (int i = 0; i < res.length; i++) {
            res[i] = res[i].trim();
        }
        return res;
    }

    /**
     * @param strings   array of strings to concatenate
     * @param separator separator string
     * @return concatenation result
     */
    public static String join(String[] strings, String separator) {
        String res = "";
        for(String s: strings){
            res+=(res.equals("")?"":separator)+s;
        }
        return res;
    }
}
